package Chapter2.Comparing.c9;

//import java.awt.*;

public class WindowDemo {
    public static void main(String[] args) {
        ThreadWindow tw = new ThreadWindow();
        Thread one = new Thread(tw,"一号窗");
        Thread two = new Thread(tw,"二号窗");
        Thread three = new Thread(tw,"三号窗");
        one.start();
        two.start();
        three.start();
    }
}

class ThreadWindow implements Runnable{
    int tickets = 100;
    int i = 1;

    @Override
    public void run() {
        while(true){
            if (tickets>0){
                System.out.println(i+":"+Thread.currentThread().getName()+"正在售票，票号为："+tickets--);
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            else {
                break;
            }
            i++;
        }
    }
}
